package com.gongzhiyun.springboot3test.controller;

import com.gongzhiyun.springboot3test.base.R;
import com.gongzhiyun.springboot3test.entity.dialogue.PrivateMessages;
import com.gongzhiyun.springboot3test.entity.user.TbUser;
import com.gongzhiyun.springboot3test.service.PrivateService;
import com.gongzhiyun.springboot3test.validate.CommonValidate;
import com.gongzhiyun.springboot3test.vo.ChatData;
import com.gongzhiyun.springboot3test.vo.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/private")
@Tag(name = "私聊相关功能")
public class PrivateMessagesController {
    private final PrivateService privateService;

    @Operation(summary = "查询登录用户的所有私聊对象",description = "查询用户的私聊列表")
    @GetMapping("")
    public R<List<UserInfo>> queryByUid(){
        return privateService.getuid();
    }

    @Operation(summary = "查询私聊对话",description = "查询私聊对话")
    @GetMapping("/{id}")
    public R<List<PrivateMessages>> getDialogue(@PathVariable Integer id){
        return privateService.getDialogue(id);
    }

    @Operation(summary = "发送私聊消息",description = "发送私聊消息")
    @PostMapping("/send")
    public R<String> send(@RequestBody @Validated(CommonValidate.add.class) PrivateMessages privateMessages){
        return privateService.send(privateMessages);
    }


    @Operation(summary = "根据名称发送私聊消息",description = "发送私聊消息")
    @PostMapping("/sendByOther")
    public R<String> sendByOther(@RequestBody TbUser tbUser){
        return privateService.sendByOther(tbUser.getUsername());
    }

    @Operation(summary = "查询未读消息数量",description = "查询未读消息数量")
    @GetMapping("/getUnreadCount/{id}")
    public R<Integer> getUnreadCount(@PathVariable("id") Integer id){
        return privateService.getUnreadCount(id);
    }

    @Operation(summary = "标记已读",description = "标记已读")
    @GetMapping("/read/{id}")
    public R<String> read(@PathVariable("id") Integer id){
        return privateService.read(id);
    }
}
